package com.by.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;


/**
 * <p><p/>
 *
 * @author boyin
 * @ClassName ByH2Util
 * @Description H2数据库
 * @date 2024/12/24 6:38
 */
public class ByH2Util extends ByJdbcUtil {
    public ByH2Util(String jdbcType) {
        super(jdbcType);
    }

    @Override
    public Connection createConnection() {
       if (this.getJdbcType() == null || !this.getJdbcType().equals("H2")){
           throw new RuntimeException("jdbc type error !");
       }
        try {
            String url = properties.getProperty("h2.url");
            String driver = properties.getProperty("h2.driver");
            String user = properties.getProperty("h2.user");
            String password = properties.getProperty("h2.password");
            Class.forName(driver);
            Connection connection = DriverManager.getConnection(url, user, password);
            System.out.println("initSql again");
            this.initSql(connection);
            return connection;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
